#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
主题: 文件路径名的操作
问题: 你需要使用路径名来获取文件名，目录名，绝对路径等等。
提示 :
"""

import os

def recipe1():
    path = '/Users/beazley/Data/data.csv'
    print(f"{path = }")

    # Get the last component of the path
    print(f"{os.path.basename(path) = }")

    # Get the directory name
    print(f"{os.path.dirname(path) = }")    

    # Join path components together
    print(f"{os.path.join('tmp', 'data', os.path.basename(path)) = }")

def recipe2():
    # Expand the user's home directory
    path = '~/Data/data.csv'
    print(f"{path = }")
    print(f"{os.path.expanduser(path) = }")

    # Split the file extension
    print(f"{os.path.splitext(path) = }")  

def main():
    print('recipe1'.center(20, '*'))
    recipe1()
    print('recipe2'.center(20, '*'))
    recipe2()

if __name__ == '__main__':
    main()
